<?php
/**
 * @fileoverview    找回密码  /注册完 重新发送邮件
 * @author          zhanglei11
 * @date            
 * @copyright       sina meila
 */
include_once '../../__global.php';
include_once SERVER_ROOT_PATH.'/include/tool/ml_tool_sendMq.php';
include(SERVER_ROOT_PATH.'/include/config/dataRule/ml_datarule_user.php');

class aj_sendEmailToReset extends ml_controller{

    private $email;
    private $uid;
    private $type;
    
    function main(){
        //    miss 获取用户信息
        $oAccount = new ml_model_dbUserAccount();
        $rs = $oAccount->getAccountByEmail($this->email);
        $row = $oAccount->get_data();
//        $oAccount->isEmailExists($this->email,$isExists);
        
        if(!$rs) {  //  账号不存在
            $this->api_output(ML_RCODE_PARAM);
        }
        $code = ml_tool_securecode::passport_encrypt($this->email);
        
        if($this->type == 1) {    //  重新发送注册激活的邮件
            $title = $row['nickname'].'，欢迎来到美啦！';
            $act_url = SITE_ROOT_URL.'/page/user/active_register.php?code='.$code;
            //    投 发邮件队列
            ml_tool_sendMq::sendMail($this->email , $title , 'register' ,$act_url, $this->nick);            
            
        }elseif ($this->type == 2) {  //  重新发送找回密码的邮件
            $url = SITE_ROOT_URL.'/page/user/setpwd.php?code='.$code;
            //投放队列
            ml_tool_sendMq::sendMail($this->email,ML_SMTP_TITLE,'findPwd',$url,$this->nick);
        }
            
        //  增加reset记录
//        $oReset = new ml_model_dbUserResetPassword();
//        $oReset->addResetPwd($uid,$code);
        
        $this->api_output(ML_RCODE_SUCC);
    }

    function initParam() {
        //$session = $this->getSession();
        
        $this->type = $this->input('type','P');
        $this->email = $this->input('email','P');    //目标用户
       
        if($this->type == 1) {
            if (empty($this->email)) {
                $this->email = $this->__visitor['email'];    //目标用户
                    $this->uid = $this->__visitor['uid'];
            }
        }
/*        elseif($this->type == 2) {
            $this->email = $this->input('email','P');    //目标用户
        }
  */       
    }

    function checkParam(){
        $this->check_referer();
        //email 判断一下格式
        if(filter_var($this->email , FILTER_VALIDATE_EMAIL) == false)
            $this->api_output(ML_RCODE_PARAM);
            
        $len = strlen($this->email);
        if($len < ML_DATARULE_USER_EMAIL_MINLEN || $len > ML_DATARULE_USER_EMAIL_MAXLEN)
            $this->api_output(ML_RCODE_PARAM);
        
    }

}

new aj_sendEmailToReset();

